package com.omt.tarjimdinek.domain.translate.entity;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;
import javax.persistence.Version;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

import org.apache.log4j.Logger;
import org.hibernate.validator.constraints.NotEmpty;

import com.google.common.base.Objects;
import com.omt.tarjimdinek.domain.islamicLibrary.entity.Sahabi;
import com.omt.tarjimdinek.domain.tv.entity.Chaine;
import com.omt.tarjimdinek.domain.tv.entity.Intervenant;
import com.omt.tarjimdinek.domain.tv.entity.Theme;
import com.omt.tarjimdinek.support.Identifiable;

/**
 * detail of video submitted
 * @author chabane
 *
 */
@Entity
@Table(name="a01_dtlvdo")
public class DetailVideo implements Identifiable<Long>, Serializable{

    private static final long serialVersionUID = 1L;
    private static final Logger log = Logger.getLogger(DetailVideo.class);
    
	/** ID SGBD */
	@Column(name="CNDTLVDO", length=11)
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private Long id;
	
	@Column(name = "VERSION", precision = 10)
    @Version
    private Integer version;
	
	/** link youtube */
	@Size(max = 45)
	@NotEmpty
	@Column(name="LILNYT", length=45, nullable=false)
	private String lienYoutube;
	
	/** channel of video */
	@NotNull
	@JoinColumn(name="CNCHN", nullable=false)
    @ManyToOne
	private Chaine chaine;
	
	/** theme of video */
	@NotNull
	@JoinColumn(name="CNTHM", nullable=false)
    @ManyToOne
	private Theme theme;
	
	/** diffusion date */
	@Temporal(TemporalType.DATE)
	@NotNull
	@Column(name="DADIF", length=45, nullable=false)
	private Date dateDiffusion;
	
	/** duration of video */
	@NotNull
	@Column(name="INDR", length=4, nullable=false)
	private Integer duree;
	
	/** number of share */
	@Column(name="INNBPTG", length=4, nullable=false)
	private Integer nombrePartage;
	
	/** list of speakers */
	@OneToMany(mappedBy="detailVideo", fetch=FetchType.LAZY)
	private List<Intervenant> listeIntervenants;

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public Integer getVersion() {
		return version;
	}

	public void setVersion(Integer version) {
		this.version = version;
	}

	public String getLienYoutube() {
		return lienYoutube;
	}

	public void setLienYoutube(String lienYoutube) {
		this.lienYoutube = lienYoutube;
	}

	public Chaine getChaine() {
		return chaine;
	}

	public void setChaine(Chaine chaine) {
		this.chaine = chaine;
	}

	public Theme getTheme() {
		return theme;
	}

	public void setTheme(Theme theme) {
		this.theme = theme;
	}

	public Date getDateDiffusion() {
		return dateDiffusion;
	}

	public void setDateDiffusion(Date dateDiffusion) {
		this.dateDiffusion = dateDiffusion;
	}

	public Integer getDuree() {
		return duree;
	}

	public void setDuree(Integer duree) {
		this.duree = duree;
	}

	public Integer getNombrePartage() {
		return nombrePartage;
	}

	public void setNombrePartage(Integer nombrePartage) {
		this.nombrePartage = nombrePartage;
	}

	public List<Intervenant> getListeIntervenants() {
		return listeIntervenants;
	}

	public void setListeIntervenants(List<Intervenant> listeIntervenants) {
		this.listeIntervenants = listeIntervenants;
	}

	@Transient
	public boolean isIdSet() {
		return id != null && id.compareTo(Long.valueOf(0)) != 0;
	}
	
	/**
     * equals implementation using a business key.
     */
    public boolean equals(Object other) {
        return this == other || (other instanceof Sahabi && hashCode() == other.hashCode());
    }

    public int hashCode() {
        int hashCode = Objects.hashCode(getId());
        return hashCode;
    }
    
    /**
     * Construct a readable string representation for this instance.
     * @see java.lang.Object#toString()
     */
    public String toString() {
        return Objects.toStringHelper(this) //
                .add("id", getId()) //
                .add("dateDiffusion", getDateDiffusion()) //
                .add("duree", getDuree()) //
                .add("lienYoutube", getLienYoutube()) //
                .add("listeIntervenants", getListeIntervenants()) //
                .add("nombrePartage", getNombrePartage()) //
                .add("theme", getTheme()) //
                .add("chaine",getChaine()) //
                .add("version", getVersion()) //
                .toString();
    }
}
